<template>
	<view>
		<view class="list-item" v-for="item in houseList" :key="item._id" @click="goDetail(item._id)">
			<image :src="item.image" mode=""></image>
			{{item.title}}-{{item.type}}-{{item.unitPrice}}
		</view>
	</view>
</template>

<script setup>
import { reactive, ref } from 'vue';
import {onReachBottom, onPullDownRefresh} from '@dcloudio/uni-app';

	const houseList = ref([])
	const pageData = reactive({
		pageNum: 1,
		pageSize: 10,
		total: 0,
		isNextPage: true
	})
	const getList = () => {
		console.log('getList')
		uniCloud.callFunction({
			name: 'getHouseList',
			data: {
				pageNum: pageData.pageNum,
				pageSize: pageData.pageSize
			},
			success(res) {
				console.log(res)
				uni.stopPullDownRefresh()
				houseList.value = [...houseList.value, ...res.result.data]
				pageData.total  = res.result.total
				const totalNum  = Math.ceil(pageData.total/pageData.pageSize)
				if(pageData.pageNum < totalNum) {
					pageData.isNextPage = true
				} else {
					pageData.isNextPage = false
				}
				
			}
			
		})
	}
	getList()
	onReachBottom(() => {
		console.log('页面触底了 ')
		if(pageData.isNextPage) {
			pageData.pageNum += 1
			getList()
		}
		
	})
	onPullDownRefresh(() => {
		pageData.pageNum = 1
		houseList.value = []
		getList()
		
	})
	const goDetail = (id) => {
		uni.navigateTo({
			url: '/pages/detail/detail?id=' + id
		})
	}
</script>

<style>
	       
</style>
